class sceneClass {
    constructor(game){
        this.game = game
        this.init()
    }

    static new (game){
        return new this(game)
    }

    init(){
        this.elements = []
        this.players = []
    }

    addArray(img, array){
        img.scene = this
        array.push(img)
    }

    update (){
        for (var e of this.elements){
            e.update()
        }
        for (var p of this.players){
            p.update()
        }
    }

    draw(){
        for (var e of this.elements){
            this.game.drawImage(e)
        }

        for (var p of this.players){
            p.draw()
        }
    }
}

class Scene extends sceneClass {
    constructor (game){
        super(game)
        this.setup()
    }         

    setup (){
        var s = this

        // 加入背景
        //var bg = Bg.new(s.game)
        //s.addArray(bg, s.elements)

        // 加入玩家
        var p = Iori.new(s.game)
        s.addArray(p, s.players)

        this.game.registerActions("KeyA", function(){p.moveLeft()})
        this.game.registerActions("KeyD", function(){p.moveRight()})
        this.game.registerActions("KeyW", function(){p.jump()})
        this.game.registerActions("KeyS", function(){p.down()})
        this.game.registerActions("KeyDKeyW", function(){p.jump_forward()})
        this.game.registerActions("KeyDKeyD", function(){p.run()})
    }
    
} 